package com.qf.pay.controller;


import com.qf.common.core.annotation.NoLogin;
import com.qf.common.core.utils.R;
import com.qf.pay.param.OrderPayParam;
import com.qf.pay.service.OrderPayService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zdl
 * @date 2025/4/1
 */
@RestController
@RequestMapping("/order/pay")
public class OrderPayController {

    @Resource
    private OrderPayService orderPayService;

    @PostMapping()
    public R<String> orderPay(@RequestBody OrderPayParam orderPayParam) {
        String qrCode = orderPayService.pay(orderPayParam);
        return R.ok(qrCode);
    }

    /**
     * 提供给支付宝或微信，异步回调的接口
     *
     * @param request
     * @param response
     */
    @PostMapping("/notify/{platformType}")
    public void notify(HttpServletRequest request, HttpServletResponse response, @PathVariable("platformType") Integer platformType) {
        orderPayService.notify(request, response,platformType);
    }

    /**
     * 检测交易订单的支付状态，并进行相应的处理
     * @param
     * @return
     */
//    @GetMapping("/status")
//    public R<?> checkPayStatus(String orderNo) {
//        orderPayService.checkPayStatus(orderNo);
//        return R.ok(status);
//    }

    @NoLogin
    @GetMapping("/return")
    public R<?> returnUrl(HttpServletRequest request, HttpServletResponse response) {
        orderPayService.returnNotify(request, response);
        return R.ok("");
    }

    @PostMapping("/refund")
    public R<String> refund(String orderNo) {
        orderPayService.refund(orderNo);
        return R.ok("成功退款");
    }

    @GetMapping("/token")
    public R<?> getToken(){
        String token = orderPayService.getToken();
        return R.ok(token);
    }
}
